#include "createtrackdialog.h"
#include "ui_createtrackdialog.h"

CreateTrackDialog::CreateTrackDialog(const bool &aContinue, QWidget *parent) :
    QDialog(parent), ui(new Ui::CreateTrackDialog), save(true)
{
    QString tmpString("Трек ");
    tmpString += QDateTime::currentDateTime().toString();
    ui->setupUi(this);
    ui->trackNameLineEdit->setText(tmpString);
    ui->continueButton->setEnabled(aContinue);
    setFixedSize(size());
}

CreateTrackDialog::~CreateTrackDialog()
{
    delete ui;
}

bool CreateTrackDialog::Result(QString &aName, bool &aSave, bool &aSetCurrent) const
{
    if(!ui->trackNameLineEdit->text().isEmpty())
    {
        aName = ui->trackNameLineEdit->text();
        aSave = ui->saveCheckBox->isChecked();
        aSetCurrent = ui->setCurrentCheckBox->isChecked();
        return true;
    }
    return false;
}

void CreateTrackDialog::on_saveCheckBox_toggled(bool checked)
{
    save = checked;
    if(!save)
    {
        ui->setCurrentCheckBox->setChecked(false);
        ui->setCurrentCheckBox->setEnabled(false);
    }
    else
        ui->setCurrentCheckBox->setEnabled(true);
}

void CreateTrackDialog::on_trackNameLineEdit_textChanged(const QString& /*arg1*/)
{
    ui->saveCheckBox->setEnabled(!ui->trackNameLineEdit->text().isEmpty());
    if(ui->trackNameLineEdit->text().isEmpty())
    {
        ui->saveCheckBox->setChecked(false);
        ui->setCurrentCheckBox->setChecked(false);
        ui->setCurrentCheckBox->setEnabled(false);
    }
    else
        ui->saveCheckBox->setChecked(save);
}
